<?php
/**
 * 客户信息查询
 */
namespace app\data\controller;
use \think\Controller;
use \think\Db;

class User extends Controller
{
    public function index()
    {


        //查询系统内置用户表用于比对
        $sys_user=db('add_name')->field('account,id')->select();

        $url_user=LOGIN_HOST.'/trader/proxy/organize/query/person/invstor/page';

        $url_user_data = array (
            'search_LIKE_userSecurity.loginName' => '',
            'search_EQ_userSecurity.state' => '',
            'page'=>'1',
            'limit'=>'1000'
        );

        //获取登录页的信息
        $content = GetPost($url_user, COOKIE_PATH,$url_user_data);
        //过滤采集数据
        $data=json_decode($content);


        //清空客户表准备重新写入信息
        if($data){
            $delete_sql="truncate table ke_custom";
            Db::execute($delete_sql);
        }else{
            sendMail(['6325610@qq.com'=>'可是','381508990@qq.com'=>'波'],'采集失败-客户信息表',$content);
            return ;
        }

        //输出内容
        $res=$data->results->content;

        $arr=array();
        //批量写入数据库
        foreach ($res as $k => $it){

            //名字
            $arr[$k]['user']=$it->userM->userInfoM->name;
            //电话
            $arr[$k]['phone']=$it->userM->userSecurityM->phone;
            //银行签约状态
            $arr[$k]['state']=$it->userM->userSecurityM->state;
            //交易账号
            $arr[$k]['account']=$it->userM->userSecurityM->exLogin;
            //昵称
            $arr[$k]['nickName']=$it->userM->userSecurityM->nickName;

            foreach ($sys_user as $sys){
                if($sys['account'] == $arr[$k]['account'] ){
                    $arr[$k]['id']=$sys['id'];
                    break;
                }
            }

        }
        //批量添加
        db("custom")->insertAll($arr);

        //开始发送邮件
        sendMail(['381508990@qq.com'=>'波'],'客户信息表采集成功',$content);

    }

}
